package cn.zwx.business.goods.controller;

import cn.zwx.base.constant.ResponseMsg;
import cn.zwx.base.validator.ValidatorUtils;
import cn.zwx.business.goods.service.GoodsService;
import cn.zwx.order.req.DeductionRepertoryReq;
import cn.zwx.order.req.QueryGoodsInfoReq;
import cn.zwx.order.resp.DeductionRepertoryResp;
import cn.zwx.order.resp.QueryGoodsInfoResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 商品服务接口
 * @projectName:rocket-mq-example
 * @see:cn.zwx.business.goods.controller
 * @author:zhangwenxue
 * @createTime:2020/10/15 14:18
 * @version:1.0
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**
     * @description 查询商品信息
     * @param req 请求参数
     * @return cn.zwx.base.constant.ResponseMsg<cn.zwx.order.resp.QueryGoodsInfoResp>
     * @author zhangwenxue
     * @createTime 2020/10/15 12:02
     **/
    @RequestMapping(value = "/query/info",method = RequestMethod.POST)
    public ResponseMsg<QueryGoodsInfoResp> queryGoodsInfo(@RequestBody QueryGoodsInfoReq req){
        //校验参数
        ValidatorUtils.validateEntity(req);
        //请求接口
        QueryGoodsInfoResp resp =  goodsService.queryGoodsInfo(req);
        //返回参数
        return ResponseMsg.success(resp);

    }


    /**
     * @description 扣减库存
     * @param req 请求参数
     * @return cn.zwx.base.constant.ResponseMsg<cn.zwx.order.resp.QueryGoodsInfoResp>
     * @author zhangwenxue
     * @createTime 2020/10/15 12:02
     **/
    @RequestMapping(value = "/update/info",method = RequestMethod.POST)
    public ResponseMsg<DeductionRepertoryResp> deductionRepertory(@RequestBody DeductionRepertoryReq req){
        //校验参数
        ValidatorUtils.validateEntity(req);
        //请求接口
        goodsService.deductionRepertory(req);
        //返回参数
        DeductionRepertoryResp resp = new DeductionRepertoryResp();
        resp.setResultType(1);
        resp.setResultMsg("处理成功!!");
        return ResponseMsg.success(resp);
    }
}
